// 题目地址：https://leetcode.cn/problems/employee-importance/

import java.util.ArrayList;
import java.util.List;


class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};

public class Test690 {
    public int getImportance(List<Employee> employees, int id) {
        // 定义一个sumimp 来计算总的重要度
        int sumimp = 0;
        // 先找到id 员工
        int i = 0;
        for (; i < employees.size(); i++) {
            if ((employees.get(i)).id == id) {
                break;
            }
        }
        sumimp += employees.get(i).importance;
        // 再看id员工的下属, 取出id员工的下属
        List<Integer> sub = new ArrayList<>();
        sub = (employees.get(i)).subordinates;
        if(sub.size()==0){
            return sumimp;
        }

        for (int j = 0; j < sub.size(); j++) {
            // 找对应的id下属的iportance值
            for (int k = 0; k < employees.size(); k++) {
                // 当id下属的直系下属没有下属时
                if(employees.get(k).subordinates.size()==0){
                    if (sub.get(j) == employees.get(k).id) {
                        sumimp += employees.get(k).importance;
                    }
                }else{
                    // 当id下属的直系下属有下属时
                    sumimp+= getImportance(employees,employees.get(k).id);
                }

            }
        }

        return sumimp;

    }


    public static void main(String[] args) {
        List<Employee> employees=new ArrayList<>();
    }



    /*public static int getImportance(List<Employee> employees, int id) {
        // 定义一个sumimp 来计算总的重要度
        int sumimp = 0;
        // 先找到id 员工
        int i = 0;
        for (; i < employees.size(); i++) {
            if ((employees.get(i)).id == id) {
                break;
            }
        }
        sumimp += employees.get(i).importance;
        // 再看id员工的下属, 取出id员工的下属
        List<Integer> sub = new ArrayList<>();
        sub = (employees.get(i)).subordinates;
        for (int j = 0; j < sub.size(); j++) {
            // 找对应的id下属的iportance值
            for (int k = 0; k < employees.size(); k++) {
                if (sub.get(j) == employees.get(k).id) {
                    sumimp += employees.get(k).importance;
                }
            }
        }
        return sumimp;
    }*/


}